package cn.flying.cloud.tool.scheme.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.flying.cloud.base.common.vo.PageRequest;
import cn.flying.cloud.base.common.vo.PageResponse;
import cn.flying.cloud.tool.scheme.entity.SchemeInfo;
import cn.flying.cloud.tool.scheme.mapper.SchemeInfoMapper;
import cn.flying.cloud.tool.scheme.service.SchemeInfoService;

/**
 * 数据库信息表 服务实现类
 *
 * @author admin
 * @since 2024-05-27 15:56:01
 */
@Service
public class SchemeInfoServiceImpl extends ServiceImpl<SchemeInfoMapper, SchemeInfo> implements SchemeInfoService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    /**
     * 分页查询数据库信息表数据
     *
     * @param request
     * @return
     */
    @Override
    public PageResponse getPageList(PageRequest<SchemeInfo> request) {
        SchemeInfo param = request.getParam();
        LambdaQueryWrapper<SchemeInfo> wrapper = getLambdaQueryWrapper(param);
        // wrapper TODO
        Page<SchemeInfo> page = this.page(new Page<>(request.getPageNum(), request.getPageSize()), wrapper);
        return new PageResponse(page.getTotal(), (int) page.getCurrent(), page.getRecords());
    }

    /**
     * 构建查询对象
     *
     * @param param
     * @return
     */
    private LambdaQueryWrapper<SchemeInfo> getLambdaQueryWrapper(SchemeInfo param) {
        LambdaQueryWrapper<SchemeInfo> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return wrapper;
    }

    /**
     * 列表查询数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @Override
    public List<SchemeInfo> getList(SchemeInfo schemeInfo) {
        LambdaQueryWrapper<SchemeInfo> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        List<SchemeInfo> list = this.list(wrapper);
        return list;
    }

    /**
     * 查询数据库信息表详情数据
     *
     * @param schemeInfo
     * @return
     */
    @Override
    public SchemeInfo getOneObj(SchemeInfo schemeInfo) {
        LambdaQueryWrapper<SchemeInfo> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.getOne(wrapper);
    }


    /**
     * 新增数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean createObj(SchemeInfo schemeInfo) {
        return this.save(schemeInfo);
    }

    /**
     * 更新数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateObj(SchemeInfo schemeInfo) {
        return this.saveOrUpdate(schemeInfo);
    }

    /**
     * 删除数据库信息表数据
     *
     * @param schemeInfo
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteObj(SchemeInfo schemeInfo) {
        LambdaQueryWrapper<SchemeInfo> wrapper = new LambdaQueryWrapper<>();
        // wrapper TODO
        return this.remove(wrapper);
    }
}
